#!/usr/bin/env python
#-*- coding:utf-8 -*-
__author__ = 'weihaoxuan'

import MySQLdb
from zabbix_grap import settings

class MysqlHelper(object):

    def __init__(self):
        self.__conn_dict = settings.conn_dict


    def Get_all(self,sql):
        try:
            conn = MySQLdb.connect(**self.__conn_dict)
            cur = conn.cursor()
            reCount = cur.execute(sql)
            data = cur.fetchall()
            conn.commit()
            cur.close()
            conn.close()
        except Exception,e:
            return False
        return data

    def Get_one_dict(self,sql):
        conn = MySQLdb.connect(**self.__conn_dict)
        cur = conn.cursor(cursorclass = MySQLdb.cursors.DictCursor)
        reCount = cur.execute(sql)
        data = cur.fetchone()
        conn.commit()
        cur.close()
        conn.close()
        return data

    def In_sql(self,sql):
        conn = MySQLdb.connect(**self.__conn_dict)
        cur = conn.cursor()
        reCount = cur.execute(sql)
        data = cur.fetchone()
        conn.commit()
        cur.close()
        conn.close()
        return data